package edu.gatech.cs2340.teamrocket.control.networking.message;

import java.io.Serializable;

/**
 * Standard communication packet.
 *
 * @author Joe Tacheron
 */
public abstract class Message implements Serializable {

    /**
     * The ID of this message
     */
    protected long messageID;
    /**
     * The payload.
     */
    protected Object[] message;

    public Message() { }

    /**
     *
     * @param messageID the ID of this Message
     */
    public Message(long messageID){
        this.messageID = messageID;
    }

    /**
     *
     * @param message the payload
     */
    public Message(Object[] message){
        this.message = message;
    }

    /**
     *
     * @param messageID the ID of this Message
     * @param message the payload
     */
    public Message(long messageID, Object[] message){
        this.message = message;
        this.messageID = messageID;
    }

    /**
     * Set the payload.
     *
     * @param message the new payload.
     */
    public void setMessage(Object[] message){
        this.message = message;
    }

    /**
     *
     * @return the Message ID
     */
    public long getMessageID(){
        return messageID;
    }

    /**
     *
     * @return the payload.
     */
    public Object[] getMessage(){
        return message;
    }

    /**
     *
     * @param i the index into the payload
     * @return payload[i]
     */
    public Object get(int i){
        return message[i];
    }

    /**
     * @param o The object to test equality on.
     * @return true if this object and o are of the same class.
     */
    // TODO: needed?
    @Override
    public boolean equals(Object o){
        if(!(o instanceof Message))
            return false;
        else
            return getClass().equals(o.getClass());
    }

    /**
     *
     * @return The class name and Message ID in parenthesis.
     */
    @Override
    public String toString(){
        return getClass().getName() + " ( ID: " + messageID + ")";
    }
}
